package com.accedo.achievements.dataaccess.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.stereotype.Component;

@Component
@Entity
@Table(name="t_badge")
public class Badge implements Serializable {

	private static final long serialVersionUID = 1599806668425002469L;
	private int id; //generated by native
	private String badge_sn; //unique & not-null
	private String badge_name; // not-null
	private Set<Achievement> achis; //many-to-many
	
	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(unique=true,
			nullable=false)
	public String getBadge_sn() {
		return badge_sn;
	}
	public void setBadge_sn(String badge_sn) {
		this.badge_sn = badge_sn;
	}
	
	@Column(nullable=false)
	public String getBadge_name() {
		return badge_name;
	}
	public void setBadge_name(String badge_name) {
		this.badge_name = badge_name;
	}
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name="t_badge_achievement", 
			joinColumns={@JoinColumn(name="badge_id")},
			inverseJoinColumns={@JoinColumn(name="achi_id")})
	public Set<Achievement> getAchis() {
		return achis;
	}
	public void setAchis(Set<Achievement> achis) {
		this.achis = achis;
	}
	
	
}
